<?
	include "include/config.inc";
	$page["title"] = "Graphs";
	$page["file"] = "graphs.html";
	show_header($page["title"],0,0);
?>

<?
	show_table_header("CONFIGURATION OF GRAPHS");
	echo "<br>";
?>

<?
	if(isset($register))
	{
		if($register=="add")
		{
			$result=add_graph($name,$width,$height);
			show_messages($result,"Graph added","Cannot add graph");
		}
		if($register=="update")
		{
			$result=update_graph($graphid,$name,$width,$height);
			show_messages($result,"Graph updated","Cannot update graph");
		}
		if($register=="delete")
		{
			$result=delete_graph($graphid);
			show_messages($result,"Graph deleted","Cannot delete graph");
			unset($graphid);
		}
	}
?>

<?
	show_table_header("GRAPHS");
	echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Name</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Width</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Height</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>";
	echo "</TR>";

	$result=DBselect("select g.graphid,g.name,g.width,g.height from graphs g order by g.name");
	echo "<CENTER>";
	$col=0;
	for($i=0;$i<DBnum_rows($result);$i++)
	{
		if($col==1)
		{
			echo "<TR BGCOLOR=#EEEEEE>";
			$col=0;
		} else
		{
			echo "<TR BGCOLOR=#DDDDDD>";
			$col=1;
		}
	
		$graphid_=DBget_field($result,$i,0);
		$name_=DBget_field($result,$i,1);
		$width_=DBget_field($result,$i,2);
		$height_=DBget_field($result,$i,3);
		echo "<TD><a href=\"graph.html?graphid=$graphid_\">$name_</a></TD>";
		echo "<TD>$width_</TD>";
		echo "<TD>$height_</TD>";
		echo "<TD><A HREF=\"graphs.html?graphid=$graphid_#form\">Change</A> - <A HREF=\"graphs.html?register=delete&graphid=$graphid_\">Delete</A></TD>";
		echo "</TR>";
	}

	echo "</TABLE>";
?>

<?
	echo "<a name=\"form\"></a>";

	if(isset($graphid))
	{
		$result=DBselect("select g.graphid,g.name,g.width,g.height from graphs g where graphid=$graphid");
		$name=DBget_field($result,0,1);
		$width=DBget_field($result,0,2);
		$height=DBget_field($result,0,3);
	}
	else
	{
		$name="";
		$width=900;
		$height=200;
	}

	echo "<br>";
	show_table2_header_begin();
	echo "New graph";

	show_table2_v_delimiter();
	echo "<form method=\"post\" action=\"graphs.html\">";
	if(isset($graphid))
	{
		echo "<input name=\"graphid\" type=\"hidden\" value=$graphid>";
	}
	echo "Name";
	show_table2_h_delimiter();
	echo "<input name=\"name\" value=\"$name\" size=32>";

	show_table2_v_delimiter();
	echo "Width";
	show_table2_h_delimiter();
	echo "<input name=\"width\" size=5 value=\"$width\">";

	show_table2_v_delimiter();
	echo "Height";
	show_table2_h_delimiter();
	echo "<input name=\"height\" size=5 value=\"$height\">";

	show_table2_v_delimiter2();
	echo "<input type=\"submit\" name=\"register\" value=\"add\">";
	if(isset($graphid))
	{
		echo "<input type=\"submit\" name=\"register\" value=\"update\">";
	}

	show_table2_header_end();
?>

<?
	show_footer();
?>
